<template>
  <div class="home">
    <div
      style="
        margin: 10px 0 0 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
      "
    >
      <div>车辆告警记录</div>
      <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item>停车场管理</el-breadcrumb-item>
          <el-breadcrumb-item>车辆管理</el-breadcrumb-item>
          <el-breadcrumb-item>车辆告警记录</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>

    <!-- 搜索区 重置区-->
    <div class="header">
      <el-input clearable v-model="vehicleNum" placeholder="车牌号码"></el-input>
      <el-select clearable v-model="deviceName" placeholder="选择设备">
        <el-option :key="v.id"
          v-for="v in device"
          :label="v.deviceName"
          :value="v.deviceName"></el-option>
      </el-select>
      <el-select clearable v-model="devicePlace" placeholder="选择位置">
        <el-option :key="v.id"
          v-for="v in device"
          :label="v.devicePlace"
          :value="v.devicePlace"></el-option>
      </el-select>
      <el-date-picker
        v-model="value1"
        type="datetimerange"
        range-separator="—"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      >
      </el-date-picker>
      <el-button type="primary" class="el-icon-search" size="medium" @click="search"
        >查询</el-button
      >
      <el-button class="el-icon-refresh" size="medium" @click="reset">重置</el-button>
    </div>

    <!-- 数据 -->
    <div style="width: auto; background: #fff">
      <div
        style="
          display: flex;
          justify-content: space-between;
          padding: 10px 0 10px 0;
        "
      >
        <p style="font-size: 15px; font-weight: bold; margin: 5px 0 0 20px">
          查询结果列表
        </p>
      </div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="序号" width="100" align="center">
        </el-table-column>
        <el-table-column prop="warnNum" label="告警编号" align="center">
        </el-table-column>
        <el-table-column prop="deviceName" label="设备名称" align="center">
        </el-table-column>
        <el-table-column prop="devicePlace" label="设备位置" align="center">
        </el-table-column>
        <el-table-column prop="warnContent" label="告警内容" align="center">
        </el-table-column>
        <el-table-column prop="vehicleNum" label="车牌号码" align="center">
        </el-table-column>
        <el-table-column prop="warnTime" label="告警时间" align="center">
          <template slot-scope="scope">
          <span>{{timeTrans(scope.row.warnTime)}}</span>
        </template>
        </el-table-column>
        <el-table-column prop="picture" label="抓拍图片" align="center">
          <template slot-scope="scope">
            <img
              :src="scope.row.picture"
              alt="图片错误"
              v-if="scope.row.picture"
            />
            <span v-else>暂无</span>
          </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              style="color: #0bb197"
              @click="set(scope.row.id), (ownerDialog = true)"
              type="text"
              size="small"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div class="block">
      <el-pagination
      @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="count"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :background="true"
        class="msg-pagination-container"
      >
      </el-pagination>
    </div>

    <!-- 详情信息弹窗 -->
    <div class="regionSet">
      <el-dialog
        title="详情信息"
        :visible.sync="ownerDialog"
        class="regionSet-el-dialog"
      >
        <!-- <div>数据检测中---{{}}</div> -->
        <div class="regionSet-header">
          <div class="regionSetBtn">
            <div class="details-box">
              <div class="details" style="margin-right: 150px">
                <div>告警编号：</div>
                <div>{{ details.warnNum }}</div>
              </div>
              <div class="details">
                <div>设备名称：</div>
                <div>{{ details.deviceName }}</div>
              </div>
            </div>
            <div class="details-box">
              <div class="details" style="margin-right: 150px">
                <div>设备位置：</div>
                <div>{{ details.devicePlace }}</div>
              </div>
              <div class="details">
                <div>告警内容：</div>
                <div>{{ details.warnContent }}</div>
              </div>
            </div>
            <div class="details-box">
              <div class="details" style="margin-right: 150px">
                <div>车牌号码：</div>
                <div>{{ details.vehicleNum }}</div>
              </div>
              <div class="details">
                <div>告警时间：</div>
                <div v-if="details.warnTime">{{ timeTrans(details.warnTime) }}</div>
              </div>
            </div>
            <div class="details-box">
              <div class="details" style="margin-right: 150px">
                <div>抓拍图片：</div>
                <div><img
              :src="details.picture"
              alt="图片错误"
              v-if="details.picture!=''"
            />
            <span v-else>暂无</span></div>
              </div>
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
//时间戳函数引用
import time from "../utils/time"
export default {
  mixins: [time],
  data: function () {
    return {
      page: 1,
      count: 5,
      total: 1,
      vehicleNum:'',
      deviceName:'',
      devicePlace: "",
      pageSize: 10,
      currentPage4: 1,
      ownerDialog: false,
      value1: [],
      tableData: [],
      details: {},
      device:[],
    };
  },
  methods: {
    //查看详情
    set: function (index) {
      console.log(index);
      this.$axios({
        url: "/smart/vehicle-warn/warn/selectById/" + index,
        method: "POST",
      }).then(({ data }) => {
        // console.log('详情数据检测',data);
          this.details = data;
      });
    },
    //改变条数
    handleSizeChange(val) {
      this.count = val;
      this.getData();
      // console.log(`每页 ${val} 条`);
    },
    //翻页
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
      // console.log(`当前页: ${val}`);
    },
    //渲染
    getData: function () {
      if(this.value1 ==null){
        this.value1 = [];
      }
      this.$axios({
        url: "/smart/vehicle-warn/selectByCondition",
        method: "POST",
        data: {
          pageNum: this.page,
          pageSize: this.count,
          vehicleNum: this.vehicleNum,
          deviceName: this.deviceName,
          devicePlace: this.devicePlace,
          startTime: this.value1[0],
          endTime: this.value1[1],
        },
      }).then(({ data }) => {
        console.log(data);
        if (data.code == '00000') {
          this.tableData = data.data.list;
          this.total = data.data.total;
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },
    //查询
    search: function () {
      this.getData();
    },
    //重置
    reset: function () {
      this.vehicleNum = "";
      this.deviceName = "";
      this.devicePlace = "";
      this.value1 = [];
      this.getData();
    },
  },
  mounted: function () {
    //初始化渲染
    this.getData();
    //获取全部设备信息
    this.$axios({
        url: "/smart/vehicle-warn/vehicleWarnList",
        method: "POST",
        data: {
          pageNum: 1,
          pageSize: 10000,
        },
      }).then(({ data }) => {
        console.log(data);
        if (data.code == '00000') {
          this.device = data.data.list;
        } else {
          this.$message.error("设备信息获取失败！");
        }
      });
  },
};
</script>

<style lang="less" scoped>
.home {
  height: 95%;
  margin: 20px 20px 0 20px;
}
.header {
  width: 100%;
  height: 80px;
  background: #fff;
  display: flex;
  align-items: center;
  margin: 30px 0 20px 0;

  .el-input,
.el-select {
  width: 200px;
  margin: 10px;
}
}
.el-icon-search {
  background: #0bb197;
  margin-left: 10px;
}
.el-icon-refresh {
  background-color: white;
  color: #c0c4cc;
  border: 1px solid #c0c4cc;
}
.el-icon-refresh:hover {
  color: #0bb197;
}
.el-pagination {
  margin-top: 30px;
  text-align: right;
}
//详情弹框
.regionSet-header {
  width: 100%;
  height: 350px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.regionSetBtn {
  width: 100%;
  height: 95%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  .details-box {
    display: flex;
    .details {
      width: 50%;
      display: flex;
      justify-content: space-between;
    }
  }
}
</style>
<style>
.msg-pagination-container.is-background .el-pager li:not(.disabled).active {
  /*当前选中页数的样式进行修改*/
  background-color: #0bb197;
  color: #fff;
}
/* // 详情信息弹窗 */

.regionSet .el-dialog__header {
  background: #0bb197;
  padding: 10px 20px 10px;
}
.regionSet .el-dialog__title {
  font-size: 15px;
  font-weight: bold;
  color: white;
}
.regionSet .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
.regionSet .el-dialog__body {
  padding: 0px 20px;
}
</style>
